package com.huatai.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.common.util.StringUtil;
import com.huatai.manage.entity.TbTrialInfoEntity;
import com.huatai.manage.mapper.TbTrialModelMapper;
import com.huatai.manage.entity.TbTrialModelEntity;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.service.TbTrialModelService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 模型表;(TbTrialModelManage)表服务实现类
 *
 * @author luoxc
 * @since 2023-03-14 14:13:39
 */
@Service("tbTrialModelManageService")
public class TbTrialModelServiceImpl extends ServiceImpl<TbTrialModelMapper, TbTrialModelEntity> implements TbTrialModelService {


	/**
	 * 分页获取模型列表
	 * @param pageQuery
	 * @return
	 */
	@Override
	public Page<TbTrialModelEntity> pageList(PageQuery<TbTrialModelEntity> pageQuery) {
		Page<TbTrialModelEntity> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
		String modelType = pageQuery.getData().getModelType();
		String modelName = pageQuery.getData().getModelName();
		LambdaQueryWrapper<TbTrialModelEntity> wrapper = Wrappers.<TbTrialModelEntity>lambdaQuery()
			.eq(StringUtil.isNotBlank(modelType), TbTrialModelEntity::getModelType, modelType)
			.like(StringUtil.isNotBlank(modelName), TbTrialModelEntity::getModelName, modelName);
		return page(page, wrapper);
	}

	/**
	 * 根据模型id集合删除数据
	 * @param modelIds
	 * @return
	 */
	@Override
	public boolean removes(List<String> modelIds) {
		if (modelIds.isEmpty()) return false;
		return remove(Wrappers.<TbTrialModelEntity>lambdaQuery().in(TbTrialModelEntity::getModelId, modelIds));
	}

	/**
	 * 根据模型id修改信息
	 * @param tbTrialModelEntity
	 * @return
	 */
	@Override
	public boolean update(TbTrialModelEntity tbTrialModelEntity) {
		return update(tbTrialModelEntity,Wrappers.<TbTrialModelEntity>lambdaUpdate()
			.eq(TbTrialModelEntity::getModelId,tbTrialModelEntity.getModelId()));
	}

	/**
	 * 根据模型id获取信息
	 * @param modelId
	 * @return
	 */
	@Override
	public TbTrialModelEntity getByModelId(String modelId) {
		return getOne(Wrappers.<TbTrialModelEntity>lambdaQuery().eq(TbTrialModelEntity::getModelId, modelId));
	}

	/**
	 * 判断数据是否存在
	 *
	 * @param modelId
	 * @return
	 */
	@Override
	public boolean isExist(String modelId) {
		long count =
			this.count(Wrappers.<TbTrialModelEntity>lambdaQuery().eq(TbTrialModelEntity::getModelId, modelId));
		return count > 0;
	}

}

